#!/usr/bin/python

import socket ,traceback
host = ''
port = 50000

try :
    s =  socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
    s.setsockopt(socket.SOL_SOCKET,socket.SO_REUSEADDR,1)
    s.setsockopt(socket.SOL_SOCKET,socket.SO_BROADCAST,1)
    s.bind((host,port))
    
    while True:
        try:
            message , address  = s.recvfrom(8192)
            print "Get data from " , address
            #
            buf = s.recv(4096)
            print buf
            print "send",
            s.sendto("from Qingluan",address)
            print "ok"
        except (KeyboardInterrupt , SystemExit):
            raise
        except:
            traceback.print_exc()
except socket.gaierror, e:
    print "error : %s" % e
except :
    traceback.print_exc()
